package com.shangcheng.server.controller;

import cn.hutool.core.collection.CollUtil;
import com.shangcheng.model.domain.SmsHomeBrand;
import com.shangcheng.model.domain.SmsHomeNewProduct;
import com.shangcheng.model.vo.PageResult;
import com.shangcheng.model.vo.result.Result;
import com.shangcheng.server.exception.BusinessException;
import com.shangcheng.server.service.SmsHomeNewProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.util.ObjectUtils;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author shiqiang
 * @version 1.0
 * @date 2022/5/12 21:39
 */
@RestController
@RequestMapping("/home/newProduct")
public class SmsHomeNewProductController {
    @Autowired
    private SmsHomeNewProductService homeNewProductService;

    /**
     * 批量添加首页新品
     * @param homeNewProductList 新品集合
     * @return
     */
    @PostMapping("/create")
    public ResponseEntity createNewPro(@RequestBody List<SmsHomeNewProduct> homeNewProductList){
        homeNewProductService.createNewPro(homeNewProductList);
        return ResponseEntity.ok(new Result(200,null,"添加成功"));
    }

    /**
     * 批量删除首页新品
     * @param ids 新品ids
     * @return
     */
    @PostMapping("/delete")
    public ResponseEntity deleteNewPro(Integer[] ids){
        homeNewProductService.deleteNewPro(ids);
        return ResponseEntity.ok(new Result(200,null,"删除成功"));
    }

    /**
     * 分页查询首页新品
     * @param pageNum
     * @param pageSize
     * @param productName
     * @param recommendStatus
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity newProList(@RequestParam(defaultValue = "1") Integer pageNum,
                                     @RequestParam(defaultValue = "10") Integer pageSize,String productName,Integer recommendStatus){
        PageResult result=homeNewProductService.newProList(pageNum,pageSize,productName,recommendStatus);
        return ResponseEntity.ok(new Result(200,result,null));
    }

    /**
     * 批量修改新品推荐状态
     * @param ids
     * @param recommendStatus
     * @return
     */
    @PostMapping("/update/recommendStatus")
    public ResponseEntity updateRecommendStatus(Integer[] ids,Integer recommendStatus){
        homeNewProductService.updateRecommendStatus(ids,recommendStatus);
        return ResponseEntity.ok(new Result(200,null,"修改成功"));
    }

    /**
     * 修改首页新品推荐排序
     * @param id
     * @param sort
     * @return
     */
    @PostMapping("/update/sort/{id}")
    public ResponseEntity updateSort(@PathVariable("id") Integer id,@RequestParam Integer sort){
        homeNewProductService.updateSort(id,sort);
        return ResponseEntity.ok(new Result(200,null,"修改成功"));
    }
}
